package com.lyz.dataStructure.JianZhiOffer.array;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 18:59
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/6/30 18:59
 *@Description:
 **/
/*
分糖果问题
 */
public class Main {
    public static int cd(int[] arr){
        if(arr==null||arr.length==0){
            return 0;
        }
        int index = nextMinIndex(arr,0);
        int res = rightCand(arr,0,index++);
        int base =1;
        int next = 0;
        int rcand= 0;
        int rbases = 0;
        while(index!= arr.length){
            if(arr[index]>arr[index-1]){
                res+= ++base;
                index ++;
            }else if(arr[index]<arr[index -1]){
                next = nextMinIndex(arr,index-1);
                rcand = rightCand(arr,index-1,next++);
                rbases = next -index +1;
                res+= rcand+(rbases > base? -base: -rbases);
                base =1;
                index =next;
            }else{
                res += 1;
                base =1;
                index++;
            }
        }
        return res;
    }

    public static  int nextMinIndex(int[] arr, int start){
        for(int i =start; i != arr.length-1;i++){
            if(arr[i]<=arr[i+1]){
                return i ;
            }
        }
        return  arr.length-1;
    }

    public static  int rightCand(int[] arr,int left,int right){
        int n =right-left+1;
        return  n+n*(n-1)/2;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            String[] st = s.split(" ");
            int[] arr = new int[st.length];
            for(int i =0; i<arr.length;i++){
                arr[i] = Integer.parseInt(st[i]);
            }
            System.out.println(cd(arr));
        }
    }
}
